package com.shiku.mianshi.controller;

import java.util.List;

import javax.annotation.Resource;

import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.xyz.commons.utils.ReqUtil;
import cn.xyz.commons.vo.JSONMessage;
import cn.xyz.mianshi.vo.Menu;

@RestController
public class MpController {
	@Resource(name = "dsForRW")
	Datastore dsForRW;

	@RequestMapping("/public/menu/list")
	public JSONMessage getMenuList() {
		Query<Menu> q = dsForRW.createQuery(Menu.class).field("userId").equal(ReqUtil.getUserId()).field("parentId")
				.equal(0);
		List<Menu> data = q.asList();
		if (null != data) {
			for (Menu menu : data) {
				q = dsForRW.createQuery(Menu.class).field("parentId").equal(menu.getId());
				menu.setMenuList(q.asList());
			}
		}
		return JSONMessage.success(null, data);
	}
}
